from typing import Optional, Any, List
from datetime import datetime
from pydantic import BaseModel, Field


class ConversionResult(BaseModel):
    """转换结果"""
    file_id: str = Field(..., description="文件ID")
    download_url: str = Field(..., description="下载URL")
    filename: str = Field(..., description="文件名")
    file_size: int = Field(..., description="文件大小（字节）")
    pages_count: int = Field(..., description="页面数量")
    created_at: datetime = Field(..., description="创建时间")
    expires_at: datetime = Field(..., description="过期时间")


class ApiResponse(BaseModel):
    """API 响应基类"""
    success: bool = Field(..., description="是否成功")
    message: str = Field(..., description="响应消息")
    data: Optional[Any] = Field(None, description="响应数据")
    error_code: Optional[str] = Field(None, description="错误代码")


class ConvertResponse(ApiResponse):
    """转换响应"""
    data: Optional[ConversionResult] = None


class BatchConvertResponse(ApiResponse):
    """批量转换响应"""
    data: Optional[List[ConversionResult]] = None


class HealthResponse(BaseModel):
    """健康检查响应"""
    status: str = Field(..., description="服务状态")
    version: str = Field(..., description="版本号")
    timestamp: datetime = Field(..., description="检查时间")
    uptime: float = Field(..., description="运行时间（秒）")


class ErrorResponse(ApiResponse):
    """错误响应"""
    success: bool = False
    
    @classmethod
    def create(cls, message: str, error_code: str = None) -> "ErrorResponse":
        return cls(
            success=False,
            message=message,
            error_code=error_code
        )